from appium.webdriver.common.appiumby import AppiumBy
from appium.webdriver.webdriver import WebDriver
from ...constants.common_sequence import DishReturnReason
from ...constants.common_sequence import SWITCH_ENV
from ...function.common_function import CommonFunction
from ...page.order_page.order_list_page import OrderListPage


class EntireReturnPage(object):
    """
    整单退单页面
    """

    def __init__(self, client):
        self.client = client
        self.driver: WebDriver = client.driver

    """
    Service Function
    """

    def insert_reason(self, reason: str):
        """
        填入理由信息
        """
        self.driver.find_element(AppiumBy.ID, f'{SWITCH_ENV}:id/et_reason').send_keys(reason)
        return self

    def screen_shoot(self, filename, path):
        """
        屏幕截图
        Params:
        -filename:文件名称
        -path:路径
        """
        CommonFunction(self.driver).screen_shoot(filename=filename, path=path)
        return self

    """
    Button Function
    """

    def select_reason(self, reason: str):
        """
        选择理由
        """
        options = self.driver.find_elements(AppiumBy.ID, f'{SWITCH_ENV}:id/tvOption')
        if reason == DishReturnReason.multiple.value:
            options[0].click()
        if reason == DishReturnReason.sellout.value:
            options[1].click()
        if reason == DishReturnReason.dishproblem.value:
            options[2].click()
        return self


    def print_return_report_confirm(self):
        """
        勾选打印退款单
        """
        self.driver.find_element(AppiumBy.ID, f'{SWITCH_ENV}:id/cb_print_return').click()
        return self

    def action_confirm(self):
        """
        确认
        """
        self.driver.find_element(AppiumBy.ID, f'{SWITCH_ENV}:id/confirmButton').click()
        return OrderListPage(self.client)
